package com.basic.backend.config;

import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    // ======== 文章队列配置 ========
    public static final String ARTICLE_QUEUE = "article.analysis.queue";
    public static final String ARTICLE_DLX_QUEUE = "article.dlx.queue";

    // ======== 图片队列配置 ========
    public static final String IMAGE_QUEUE = "image.analysis.queue";
    public static final String IMAGE_DLX_QUEUE = "image.dlx.queue";

    // ======== 文章队列体系 ========
    @Bean
    public Queue articleQueue() {
        return new Queue(ARTICLE_QUEUE); // 只声明基础队列
    }

    @Bean
    public Queue articleDlxQueue() {
        return new Queue(ARTICLE_DLX_QUEUE);
    }

    // ======== 图片队列体系 ========
    @Bean
    public Queue imageQueue() {
        return new Queue(IMAGE_QUEUE); // 只声明基础队列
    }

    @Bean
    public Queue imageDlxQueue() {
        return new Queue(IMAGE_DLX_QUEUE);
    }

    // ======== 消息序列化配置 ========
    @Bean
    public MessageConverter jsonMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    // ======== Rabbit模板配置 ========
    @Bean
    public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
        RabbitTemplate template = new RabbitTemplate(connectionFactory);
        template.setMessageConverter(jsonMessageConverter());
        return template;
    }
}